package com.buildings.adapter;

import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.buildings.R;
import com.buildings.activity.table.CraterActivity;
import com.buildings.activity.table.DrillHoleActivity;
import com.buildings.activity.table.FaultSvyPointActivity;
import com.buildings.activity.table.GeoGeomorphySvyPointActivity;
import com.buildings.activity.table.GeochemicalSvyLineActivity;
import com.buildings.activity.table.GeochemicalSvyPointActivity;
import com.buildings.activity.table.GeologicalSvyLineActivity;
import com.buildings.activity.table.GeologicalSvyPlanningLineActivity;
import com.buildings.activity.table.GeologicalSvyPlanningPtActivity;
import com.buildings.activity.table.GeologicalSvyPointActivity;
import com.buildings.activity.table.GeomorStationActivity;
import com.buildings.activity.table.GeomorphySvyLineActivity;
import com.buildings.activity.table.GeomorphySvyPointActivity;
import com.buildings.activity.table.GeomorphySvyReProfActivity;
import com.buildings.activity.table.GeomorphySvyRegionActivity;
import com.buildings.activity.table.GeomorphySvySamplePointActivity;
import com.buildings.activity.table.GeophySvyLineActivity;
import com.buildings.activity.table.GeophySvyPointActivity;
import com.buildings.activity.table.LavaActivity;
import com.buildings.activity.table.SamplePointActivity;
import com.buildings.activity.table.StratigraphySvyPointActivity;
import com.buildings.activity.table.TanCaodianActivity;
import com.buildings.activity.table.VolcanicSamplePointActivity;
import com.buildings.activity.table.VolcanicSvyPointActivity;
import com.esri.arcgisruntime.mapping.view.Graphic;

import java.util.List;

public class TablePointAdater extends RecyclerView.Adapter<TablePointAdater.ViewHolder> {
    private AppCompatActivity activity;
    private List<Graphic> arcgisPoint;

    public TablePointAdater(AppCompatActivity activity, List<Graphic> arcgisPoint) {
        this.activity = activity;
        this.arcgisPoint = arcgisPoint;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_table_point, parent, false);
        TablePointAdater.ViewHolder holder = new TablePointAdater.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Graphic graphic = arcgisPoint.get(position);
        String type = (String) graphic.getAttributes().get("type");
        String uuid = (String) graphic.getAttributes().get("uuid");
        int isLine = (int) graphic.getAttributes().get("isLine");
        long _id = (long) graphic.getAttributes().get("_id");
        String text = "";
        switch (type) {
            case "1":
                text = "地质调查规划路线-线";
                break;
            case "2":
                text = "地质调查规划点-点";
                break;
            case "3":
                text = "断层观测点-点";
                break;
            case "4":
                text = "地质地貌调查观测点-点";
                break;
            case "5":
                text = "地质调查路线-线";
                break;
            case "6":
                text = "地质调查观测点-点";
                break;
            case "7":
                text = "地层观测点-点";
                break;
            case "8":
                text = "探槽-点";
                break;
            case "9":
                text = "微地貌测量线-线";
                break;
            case "10":
                text = "微地貌测量点-点";
                break;
            case "11":
                text = "微地貌测量面-面";
                break;
            case "12":
                text = "微地貌面测量切线-线";
                break;
            case "13":
                text = "微地貌测量采样点-点";
                break;
            case "14":
                text = "微地貌测量基站点-点";
                break;
            case "15":
                text = "钻孔-点";
                break;
            case "16":
                text = "采样点-点";
                break;
            case "17":
                text = "地球物理测线-线";
                break;
            case "18":
                text = "地球物理测点-点";
                break;
            case "19":
                text = "地球化学探测测线-线";
                break;
            case "20":
                text = "地球化学探测测点-点";
                break;
            case "21":
                text = "火山口-点";
                break;
            case "22":
                text = "熔岩流-面";
                break;
            case "23":
                text = "火山采样点-点";
                break;
            default:
                text = "火山调查观测点-点";
                break;
        }
        holder.tv_text.setText(text);
        holder.tv_text.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jumpTableDetail(type,uuid,isLine,_id);
            }
        });
    }

    @Override
    public int getItemCount() {
        return null == arcgisPoint ? 0 : arcgisPoint.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView tv_text;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_text = itemView.findViewById(R.id.tv_text);
        }
    }

    private void jumpTableDetail(String selectTableId, String uuId, int isLine,long _id) {
        Intent intent;
        switch (selectTableId) {
            case "1":
                intent = new Intent(activity, GeologicalSvyPlanningLineActivity.class);
                break;
            case "2":
                intent = new Intent(activity, GeologicalSvyPlanningPtActivity.class);
                break;
            case "3":
                intent = new Intent(activity, FaultSvyPointActivity.class);
                break;
            case "4":
                intent = new Intent(activity, GeoGeomorphySvyPointActivity.class);
                break;
            case "5":
                intent = new Intent(activity, GeologicalSvyLineActivity.class);
                break;
            case "6":
                intent = new Intent(activity, GeologicalSvyPointActivity.class);
                break;
            case "7":
                intent = new Intent(activity, StratigraphySvyPointActivity.class);
                break;
            case "8":
                intent = new Intent(activity, TanCaodianActivity.class);
                break;
            case "9":
                intent = new Intent(activity, GeomorphySvyLineActivity.class);
                break;
            case "10":
                intent = new Intent(activity, GeomorphySvyPointActivity.class);
                break;
            case "11":
                intent = new Intent(activity, GeomorphySvyRegionActivity.class);
                break;
            case "12":
                intent = new Intent(activity, GeomorphySvyReProfActivity.class);
                break;
            case "13":
                intent = new Intent(activity, GeomorphySvySamplePointActivity.class);
                break;
            case "14":
                intent = new Intent(activity, GeomorStationActivity.class);
                break;
            case "15":
                intent = new Intent(activity, DrillHoleActivity.class);
                break;
            case "16":
                intent = new Intent(activity, SamplePointActivity.class);
                break;
            case "17":
                //todo 没测试
                intent = new Intent(activity, GeophySvyLineActivity.class);
                break;
            case "18":
                //todo 没测试
                intent = new Intent(activity, GeophySvyPointActivity.class);
                break;
            case "19":
                //todo 没测试
                intent = new Intent(activity, GeochemicalSvyLineActivity.class);
                break;
            case "20":
                intent = new Intent(activity, GeochemicalSvyPointActivity.class);
                break;
            case "21":
                intent = new Intent(activity, CraterActivity.class);
                break;
            case "22":
                intent = new Intent(activity, LavaActivity.class);
                break;
            case "23":
                intent = new Intent(activity, VolcanicSamplePointActivity.class);
                break;
            default:
                intent = new Intent(activity, VolcanicSvyPointActivity.class);
                break;
        }

        intent.putExtra("uuid", uuId);
        if (1 == isLine){
            intent.putExtra("joninType", 1);
            intent.putExtra("isOnLine", true);
        }else {
            intent.putExtra("joninType", 2);
            intent.putExtra("isOnLine", false);
            intent.putExtra("_id", _id);
        }
        activity.startActivity(intent);
    }
}
